package {
  import flash.display.Sprite;
  import flash.display.StageAlign;
  import flash.system.Security;
  import flash.external.ExternalInterface;

  public class PieChartController extends Sprite {
    private var pie:PieChart;

    public function PieChartController() {
      Security.allowDomain('*');

      stage.scaleMode = 'noScale';
      stage.align = StageAlign.TOP_LEFT;
      ExternalInterface.addCallback("draw", draw);
      pie = new PieChart(stage.stageWidth*.5, stage.stageHeight*.5, Math.min(stage.stageWidth, stage.stageHeight)*.4);
      addChild(pie);
    }

    private function draw(data:Array):void {
      pie.clearData();
      for (var i:int=0; i<data.length; i++) {
        pie.addData(data[i].value, data[i].label);
      }
      pie.paint();
    }
  }


}
